package com.intertid.mongodb.factory
import com.intertid.mongodb.MongoDBTemplate
import com.mongodb.Mongo

object MongoDBTemplateFactory {

  private val lockObject = new Object

  private[mongodb] var instance: MongoDBTemplate = _;

  def createInstance(mongo: Mongo, dbName: String): MongoDBTemplate = {
    lockObject.synchronized {
      if (instance == null) {
        instance = new MongoDBTemplate(mongo, dbName);
      }

      return instance;
    }
  }

  def getCurrentTemplate(): MongoDBTemplate = {
    lockObject.synchronized {
      return instance;
    }
  }
}